<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../0_assets/vue2.js"></script>
</head>

<body>
    <div id="app">
        <h1>我是爹，下面是我的儿子</h1>
        <child @handlechangename="handleChangeName" :mika-child-name="mikaChildName"
            :mika-child-nick-name="mikaChildNickName"></child>
    </div>
    <script>
        let app = new Vue({
            el: '#app',
            data() {
                return {
                    parentName: 'mika-parent',
                    mikaChildName: 'mika-child',
                    mikaChildNickName: '狗子'
                }
            },
            methods: {
                handleChangeName(wantName) {
                    this.mikaChildName = wantName;
                }
            },
            components: {
                child: {
                    template:
                        `
                    <div>
                         <li>爸爸给我的名字: {{ mikaChildName }}</li>
                         <li>爸爸给我的外号: {{ mikaChildNickName }}</li>
                         你想改名为: <input type="text" v-model="wantName"/>
                         <button @click="handlechangename">爹，给我改名吧</button>
                    </div>
                    `,
                    methods: {
                        handlechangename() {
                            this.$emit('handlechangename', this.wantName);
                        }
                    },
                    data() {
                        return {
                            wantName: ''
                        }
                    },
                    props: ['mikaChildName', 'mikaChildNickName']
                }
            }
        })
    </script>
</body>

</html>